<?php
namespace Base\Test;

class TestCase extends \PHPUnit_Framework_TestCase {
    protected static $_app;

    public function setUp(){
        $application = \Yaf\Registry::get('application');
        if (!$application) {
            self::$_app = (new \Yaf\Application(APP_CONF . '/application.ini'))->bootstrap();
            \Yaf\Registry::set('application', self::$_app);
        }else{
            self::$_app = $application;
        }
    }

    protected function execRequest($method, $controller, $params = array()){
        $request = new \Yaf\Request\Simple($method, 'index', $controller, 'index', $params);
        if(strtolower($method) === "post"){
            $_POST = $request->getParams();
        }else{
            $_GET = $request->getParams();
        }
        self::$_app->getDispatcher()->dispatch($request);
        $result = \Yaf\Registry::get('test_response');
        return json_decode($result, true)?:$result; // 兼容改前的情况
    }
}